<?php

$IS_HEZUO = false;
if ($argv[1] == 'hezuo') {
    $IS_HEZUO = true;
}

require_once dirname(__FILE__) . '/init.php';
$timeStart = time();

$arr_installed_subdomains = get_all_installed_site_subdomains();
$arr_installed_maindomains = get_main_domains_by_subdomains($arr_installed_subdomains);
$arr_installed_maindomains = array_unique(array_filter($arr_installed_maindomains));
$allInstall_Maindomains = $arr_installed_maindomains;
$arr_installed_subdomains = array_unique(array_filter($arr_installed_subdomains));
$allInstall_Subdomains = $arr_installed_subdomains;
$arrVpsData = require_once dirname(__FILE__) . '/input/vpslist.config.php';

$TIMESTART = date('Y-m-d H:i:s');


$cacheShotDownTime = dirname(__FILE__) . '/data/shutdown-time/';

$arrFetchHttpResult = array();
$allInstall_Maindomains_Data = array();

#如果是合作建站,则只取合作的站点
if ($IS_HEZUO) {
    $allInstall_Subdomains = getArrayFromFile(dirname(__FILE__) . '/hezuodomain.txt');
}

foreach ($allInstall_Subdomains as $itemDomain) {
    $arrDomainInfo = explode('.', $itemDomain);
    if (count($arrDomainInfo) == 3) {
        if ($arrDomainInfo[0] == 'www') {
            $allInstall_Maindomains_Data[] = $itemDomain;
        }
    }
    if (count($arrDomainInfo) == 2) {
        $allInstall_Maindomains_Data[] = 'www.' . $itemDomain;
    }
}

$allInstall_Maindomains_Data = array_unique(array_filter($allInstall_Maindomains_Data));


$HTMLBODY = '';
$HTMLBODY.= '<b>Stat By [' . getLocalIp() . ']搜索引擎收录量统计,(总计:' . count($allInstall_Maindomains_Data) . '个)</b>
          <table border="1" width="100%" bordercolorlight="#C0C0C0" bordercolordark="#C0C0C0" style="border-collapse: collapse;font-size: 14px;">';
$HTMLBODY.='<tr height="35">
    <td width="150" bgcolor="#CCCCFF"><b>域名</b></td>
	<td width="80" bgcolor="#CCCCFF"><b>百度</b></td>
    <td width="80" bgcolor="#CCCCFF"><b>Google</b></td>
    <td width="80" bgcolor="#CCCCFF"><b>搜狗</b></td>
    <td width="80" bgcolor="#CCCCFF"><b>360搜索</b></td>
	<td width="100" bgcolor="#CCCCFF"><b>请求时间</b></td>
	<td width="100" bgcolor="#CCCCFF"><b>查询详情</b></td>
	</tr>
    ';

foreach ($allInstall_Maindomains_Data as $domain) {
    $HTMLBODY.='
	<tr height="35">
    <td>' . $domain . '</td>
	<td>' . getBaiduIndexCount($domain) . '</td>
	<td>' . getGoogleIndexCount($domain) . '</td>
	<td>' . getSogouIndexCount($domain) . '</td>
    <td>' . get360IndexCount($domain) . '</td>
    <td>' . date('Y-m-d H:i:s') . '</td>
    <td>' . $days_domain . '</td>
	</tr>
    ';
    #sleep(2);
}

$HTMLBODY.= '</table>';

$fileReport = dirname(__FILE__) . '/data/report/' . date('Y-m-d') . '/Se-Report.html';
FCheckDir($fileReport);
file_put_contents($fileReport, $HTMLBODY);

$timeEnd = time();
$HTMLBODY.='<hr />总计耗时:' . ($timeEnd - $timeStart) . '秒<hr />';
post_email_by_sae('搜索引擎收录查询统计(总计:' . count($allInstall_Maindomains_Data) . '个)[' . date('Y-m-d H:i:s') . ']', $HTMLBODY, $arrUsers);
post_email_by_smtp('搜索引擎收录查询统计(总计:' . count($allInstall_Maindomains_Data) . '个)[' . date('Y-m-d H:i:s') . ']', $HTMLBODY, $arrUsers);
?>